import { defineStore } from 'pinia'
import { ref } from 'vue'
//第一个参数: 名字,唯一性
//第二个参数: 函数,内部定义状态的所有内容
//返回值----->函数
export const useOpenIdStore = defineStore(
  'openid',
  () => {
    //定义状态的内容

    //1.响应式变量

    const openid = ref()
    //2.定义一个函数,

    const setopenId = (val: any) => {
      console.log(val)

      openid.value = val
      console.log('openid:' + openid.value)
    }
    //3.函数,移除token的值
    const removeOpenId = () => {
      openid.value = ''
    }

    return {
      openid,
      setopenId,
      removeOpenId,
    }
  },
  {
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
